package com.qiangesoft.blog.controller.manage;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.system.entity.SysDictData;
import com.qiangesoft.blog.system.pojo.vo.DictDataVO;
import com.qiangesoft.blog.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/dictData")
@Api(tags = "字典数据管理")
@RequiredArgsConstructor
public class SysDictDataController {

    private final ISysDictDataService dictDataService;

    @GetMapping(value = "/list")
    @ApiOperation(value = "字典数据列表")
    public PageResultVO<SysDictData> list(PageQuery pageQuery, Long dictId, Boolean isPublish) {
        return dictDataService.listDictData(pageQuery, dictId, isPublish);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "添加字典数据", httpMethod = "POST", response = ResponseResult.class, notes = "添加字典数据")
    @OperationLog(value = "添加字典数据")
    public void insert(@RequestBody SysDictData dictData) {
        dictDataService.insertDictData(dictData);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改字典数据", httpMethod = "POST", response = ResponseResult.class, notes = "修改字典数据")
    @OperationLog(value = "修改字典数据")
    public void update(@RequestBody SysDictData dictData) {
        dictDataService.updateDictData(dictData);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除字典数据", httpMethod = "DELETE", response = ResponseResult.class, notes = "删除字典数据")
    @OperationLog(value = "删除字典数据")
    public void deleteDictData(Long id) {
        dictDataService.deleteDictData(id);
    }

    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除字典数据", httpMethod = "DELETE", response = ResponseResult.class, notes = "批量删除字典数据")
    @OperationLog(value = "批量删除字典数据")
    public void deleteBatch(@RequestBody List<Long> ids) {
        dictDataService.deleteBatch(ids);
    }

    @RequestMapping(value = "/getDataByDictType", method = RequestMethod.POST)
    public Map<String, DictDataVO> getDataByDictType(@RequestBody List<String> types) {
        return dictDataService.getDataByDictType(types);
    }
}

